<template>
  <div class="channel-wx-ma">
    <BasicForm @register="registerForm" @submit="handleSubmit" :class="prefixCls"> 
      <template #formFooter>
        <a-button :class="prefixCls + '-submit'" @click="handleSubmit" type="primary" :loading="loading" style="margin-right: 0.9rem">确定</a-button>
      </template>
    </BasicForm>
  </div>
</template>
<script lang="ts" setup>
import {ref} from 'vue'
import {BasicForm} from '/@/components/Form/index';
import {FormSchema} from '/@/components/Table';
import {UploadBizType} from '/@/enums/uploadEnum';
import {ConfigFormProps, useConfigForm} from '/@/hooks/my/useConfigForm'
import {ConfigKey} from '/@/views/system/config/config.model';

const emit = defineEmits(['query-success'])

const prefixCls = ref('channel-wx-ma-from')

const formSchema: FormSchema[] = [
  {
    field: 'baseDivider',
    label: "小程序信息",
    component: "Divider"
  },
  {
    field: 'name',
    label: '小程序名称',
    component: 'Input',
    required: true
  },
  {
    field: 'accountId',
    label: '小程序账号ID',
    component: 'Input',
    required: true
  },
  {
    label: '小程序二维码',
    field: 'qrCodeUrl',
    component: 'JImageUpload',
    componentProps: {
      fileMax:1,
      bizType: UploadBizType.GENERAL_IMAGE
    },
  },

  {
    field: 'mpDevDivider',
    label: "小程序开发信息",
    component: "Divider"
  },
  {
    field: 'appId',
    label: '应用ID',
    required: true,
    helpMessage: [
      '描述: AppID是小程序开发识别码，配合AppSecret可调用小程序的接口能力。',
      "地址: <a target='_blank' href='https://mp.weixin.qq.com/wxamp/devprofile/get_profile'>官网</a>",
      "入口: 左侧菜单->开发管理->开发设置"
    ],
    component: 'Input',
  },
  {
    label: '应用密钥',
    field: 'appSecret',
    required: true,
    helpMessage: [
      'AppSecret是校验小程序开发者身份的密钥，具有极高的安全性'
    ],
    component: 'Input'
  },

  {
    field: 'msgPushDivider',
    label: "消息推送配置",
    component: "Divider"
  },
  {
    field: 'msgPushUrl',
    label: 'URL',
    helpMessage: [ '指定当前后端服务接口用于接收微信推送的消息'],
    component: 'Input',
  },
  {
    label: 'Token',
    field: 'token',
    required: true,
    helpMessage: [ '必须为英文或数字' ],
    rules: [
      { required: true, message: 'Token不能为空' },
      { min: 5, max: 32, message: '长度在 5 到 32 个字符', trigger: 'blur' },
    ],
    component: 'Input'
  },

  {
    label: 'encodingAESKey',
    field: 'encodingAesKey',
    rules: [
      { required: true, message: 'EncodingAESKey不能为空' },
      { min: 1, max: 43, message: '长度在 1 到 43 个字符', trigger: 'blur' },
    ],
    helpMessage: [ '消息加密密钥由43位字符组成，可随机修改，字符范围为A-Z，a-z，0-9。' ],
    component: 'Input'
  },

  {
    field: 'domainDivider',
    label: "服务器域名设置",
    component: "Divider"
  },
  {
    field: 'requestUrl',
    label: 'request合法域名',
    component: 'Input',
  },
  {
    field: 'socketUrl',
    label: 'socket合法域名',
    component: 'Input',
  },
  {
    field: 'uploadFileUrl',
    label: 'uploadFile合法域名',
    component: 'Input',
  },
  {
    field: 'downloadFileUrl',
    label: 'downloadFile合法域名',
    component: 'Input',
  },
];

const configFromProps : ConfigFormProps = {
  configKey: ConfigKey.WX_MA,
  schemas: formSchema,
  labelWidth: 160
}

const { registerForm, handleSubmit, loading } = useConfigForm(configFromProps, emit)
</script>


<style lang="less" scoped>
.channel-wx-ma-from {
  width: 700px;
  &-submit {
    margin-left: 160px
  }
}

.channel-wx-ma {
  // padding: 10px;
  // background-color: #fff;
  // height: 98%;
}



</style>
